package com.ruoyi.zhgd.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Arrays;
import java.util.Map;

import com.ruoyi.zhgd.util.PageUtils;
import com.ruoyi.zhgd.util.Query;
import com.ruoyi.zhgd.dto.TensionProcessDto;
import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckLogin;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.zhgd.domain.vo.TensionProcessVo;
import com.ruoyi.zhgd.domain.bo.TensionProcessBo;
import com.ruoyi.zhgd.service.ITensionProcessService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 【请填写功能名称】
 *
 * @author zyb
 * @date 2023-09-21
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/zhgd/process")
public class TensionProcessController extends BaseController {

    private final ITensionProcessService iTensionProcessService;

    /**
     * 查询【请填写功能名称】列表
     */
    @SaCheckLogin
    @GetMapping("/list")
    public TableDataInfo<TensionProcessVo> list(TensionProcessBo bo, PageQuery pageQuery) {
        return iTensionProcessService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出【请填写功能名称】列表
     */
    @SaCheckLogin
    @Log(title = "【请填写功能名称】", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(TensionProcessBo bo, HttpServletResponse response) {
        List<TensionProcessVo> list = iTensionProcessService.queryList(bo);
        ExcelUtil.exportExcel(list, "【请填写功能名称】", TensionProcessVo.class, response);
    }

    /**
     * 获取【请填写功能名称】详细信息
     *
     * @param id 主键
     */
    @SaCheckLogin
    @GetMapping("/{id}")
    public R<TensionProcessVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable String id) {
        return R.ok(iTensionProcessService.queryById(id));
    }

    /**
     * 新增【请填写功能名称】
     */
    @SaCheckLogin
    @Log(title = "【请填写功能名称】", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody TensionProcessBo bo) {
        return toAjax(iTensionProcessService.insertByBo(bo));
    }

    /**
     * 修改【请填写功能名称】
     */
    @SaCheckLogin
    @Log(title = "【请填写功能名称】", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody TensionProcessBo bo) {
        return toAjax(iTensionProcessService.updateByBo(bo));
    }

    /**
     * 删除【请填写功能名称】
     *
     * @param ids 主键串
     */
    @SaCheckLogin
    @Log(title = "【请填写功能名称】", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable String[] ids) {
        return toAjax(iTensionProcessService.deleteWithValidByIds(Arrays.asList(ids), true));
    }

    @SaCheckLogin
    @GetMapping("/tensionProcessList")
    public R tensionProcessList(@RequestParam Map<String,Object> params,
                                @RequestParam(value = "pageNum" , required = false) Integer pageNum,
                                @RequestParam(value = "pageSize" , required = false) Integer pageSize){
        Map<String, Object> paramMap = new HashMap<>();
        paramMap.put("page",pageNum);
        paramMap.put("limit",pageSize);
        PageUtils tensionProcessList = iTensionProcessService.tensionProcessList(new Query(paramMap).getPage(), params);
        return R.ok(tensionProcessList);
    }

    /**
     * 根据单个结果查询过程数据
     * @param params
     * @return
     */
    @SaCheckLogin
    @GetMapping("/holeNumber")
    public R selectHouleNumber(@RequestParam Map<String,Object> params,
                               @RequestParam(value = "pageNum" , required = false) Integer pageNum,
                               @RequestParam(value = "pageSize" , required = false) Integer pageSize){
        Map<String, Object> paramMap = new HashMap<>();
        paramMap.put("page",pageNum);
        paramMap.put("limit",pageSize);
        PageUtils tensionProcessVos = iTensionProcessService.selectHouleNumber(new Query(paramMap).getPage(),params);
        return R.ok(tensionProcessVos);
    }

    /**
     * 数据分析接口
     * @param params
     * @return
     */
    @GetMapping("/holeNumberSjfx")
    public  R holeNumberSjfx(@RequestParam Map<String,Object> params){
        List<TensionProcessDto> tensionProcessDtos = iTensionProcessService.holeNumberSjfx(params);
        return R.ok(tensionProcessDtos);
    }
}
